cmake_minimum_required(VERSION 2.6)
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)

project(nio)

set(Boost_USE_STATIC_LIBS ON)
find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})

option(64BIT "64 bits" TRUE)

if (64BIT)
add_definitions(-D__64BIT__)
endif()

option(WINDOWS "64 bits" FALSE)

if (WINDOWS)
add_definitions(-D__WINDOWS__)
add_definitions(-D_WIN32_WINNT=0x0501)
add_definitions(-W3)
else ()
add_definitions(-D__LINUX__)
add_definitions(-Wall)
	if (CMAKE_COMPILER_IS_GNUCXX)
	add_definitions(-std=gnu++0x)
	else ()
	add_definitions(-std=stdc++11)
	endif()
endif()

if (DEBUG)
add_definitions(-D__DEBUG__)
endif()

set(nio_SOURCES
	nio/Types.hpp
	
	nio/base/TimeUtil.hpp
	nio/base/Queue.hpp
	nio/base/NonMutex.hpp
	nio/base/Mutex.hpp
	nio/base/LockGuard.hpp
	nio/base/Thread.hpp
	src/base/Thread.cc
	
	nio/net/Socket.hpp
	src/net/Socket.cc
	nio/net/EventHandler.hpp
	nio/net/Reactor.hpp
	nio/net/EventLoop.hpp
	src/net/EventLoop.cc
	nio/net/ConnectionFactory.hpp
	src/net/ConnectionFactory.cc
	nio/net/Connection.hpp
	src/net/Connection.cc
	nio/net/ConnectionStream.hpp
	src/net/ConnectionStream.cc
	nio/net/ConnectionInputStream.hpp
    src/net/ConnectionInputStream.cc
    nio/net/ConnectionOutputStream.hpp
    src/net/ConnectionOutputStream.cc
	nio/net/Acceptor.hpp
	src/net/Acceptor.cc
	nio/net/ServerThread.hpp
	src/net/ServerThread.cc
	nio/net/Server.hpp
	src/net/Server.cc
)

if (WINDOWS)
set(plat_SRC
    nio/net/detail/SelectReactor.hpp
    src/net/detail/SelectReactor.cc
)
else()
set(plat_SRC
    nio/net/detail/EpollReactor.hpp
    src/net/detail/EpollReactor.cc
)
endif()

include_directories( 
	${PROJECT_SOURCE_DIR}
)

add_library(nio STATIC ${nio_SOURCES} ${plat_SRC})